grammar := laban
CPPFLAGS := -I./ -c
CC := g++
CFLAGS := 
opath := ../../.objs/
objects := $(grammar)Parser.o $(grammar)Lexer.o
depends := $(objects:.o=.d)
cpps := $(objects:.o=.cpp)

.PHONY:	clean

all:	$(depends)
	g++ $(CPPFLAGS) $(cpps)
	mv $(grammar)Lexer.o ../../.objs/$(grammar)Lexer.o
	mv $(grammar)Parser.o ../../.objs/$(grammar)Parser.o


ifeq ($(findstring $(MAKECMDGOALS), clean),)
-include $(depends)
endif

%.d:	%.cpp
	$(CC) -I./ -M $< > $@

$(grammar)Lexer.cpp:	$(grammar)Lexer.c
	cp $(grammar)Lexer.c $(grammar)Lexer.cpp

$(grammar)Parser.cpp:	$(grammar)Parser.c
	cp $(grammar)Parser.c $(grammar)Parser.cpp
	
$(grammar)Lexer.c $(grammar)Parser.c:	$(grammar).g
	java -cp ../../3rd/antlr-3.2.jar org.antlr.Tool $(grammar).g

clean:	
	rm -rf *.c $(grammar)Lexer.h $(grammar)Parser.h *.tokens *.d *.cpp
	rm -f ../../.objs/$(grammar)Lexer.o
	rm -f ../../.objs/$(grammar)Parser.o
